﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CustomMapinfoWindows.ViewModels
{
    /// <summary>
    /// A view model base for Mapinfo file types, contains basic properties needed for working with
    /// Mapinfo files.
    /// </summary>
    public abstract class MapinfoFileViewModel : TreeViewItemViewModel, IHasPath
    {
        private bool pathchecking;
        private string fullpath;
        public MapinfoFileViewModel(string filePath, TreeViewItemViewModel parent, bool lazyLoad, bool pathChecking)
            : base(parent, lazyLoad)
        {
            this.pathchecking = pathChecking;
            this.Name = Path.GetFileNameWithoutExtension(filePath);
            this.FullPath = filePath;
        }

        /// <summary>
        /// Returns true if the file couldn't not be found at the supplied location.
        /// </summary>
        public bool NotFound { get; set; }

        /// <summary>
        /// Gets or sets the friendly name for the Mapinfo file.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the full path to the Mapinfo file.
        /// </summary>
        public string FullPath
        {
            get
            {
                return this.fullpath;
            }
            set
            {
                if (this.pathchecking && !File.Exists(value))
                {
                    this.NotFound = true;
                }
                this.fullpath = value;
            }
        }

        /// <summary>
        /// Opens the current file in the running instance of Mapinfo.
        /// </summary>
        public abstract void OpenFile();
    }
}
